<?php

/*
  ***
  *********
  *********
  *********此页面需要传入的数据：
  ********* 1、学校（地区）$_SESSION[sid]
  ********* 2、分类id，由url传入，list.php?gy_class=...&，  $class
  *********
  *********
  ***
 */
session_start();
$_SESSION[sid]='1';

include_once '../web_inc.php';
include_once ROOT_PATH.'/config/db_conn.php';
include_once './inc/gy_info_class.php';
include_once './inc/subpage.class.php';  //分页函数
include_once './smarty_inc.php';



$in=new getInfo_gy();

/*
  ***
  ***第一步：：：：判断学校分类传值，值为用户所属学校，如果为空跳转回验证页面qzone/check.php
  ***
*/
if(!empty($_SESSION[sid])){
	$shool_id=$_SESSION[sid];
}else{
	echo "<script>window.location.href='../../qzone/index.php?url=gy/list.php';</script>";
}

/*
  ***
  ***第二步：：：：获取分类传值
  ***
*/
if(empty($_GET[gy_class])){
	$class=3;
}else{
	$class=$_GET[gy_class]; 
}
//注意下面的分类url也要加入&gy_class=,$subPages=new SubPages($page_size,$nums,$pageCurrent,$sub_pages,"?action=setpage&gy_class=$class&p=",2);

//获取大分类
$qu=mysql_query("select * from gy_class where id=$class");
$cla=mysql_fetch_array($qu);

$smarty->assign("bigfenlei",$cla[name]);
//获取子分类
$qu2=mysql_query("select * from gy_class where up=$class");
while($cla2=mysql_fetch_array($qu2)){
	$fenlei[]=array("name"=>$cla2[name],"id"=>$cla2[id]);
	$smarty->assign("small_fenlei",$fenlei);
}



/*
  ***
  ***第三步：：：：获取分类信息，列表，可以输出的表为：gylist   gylist_2   user   school
  ***
*/
//$get=mysql_fetch_array($qu2);
//echo $get[id];
if($cla[up]==0){
	$sql=mysql_query("select COUNT(gylist.id) as num from gylist INNER JOIN gy_class ON gylist.class_id=gy_class.id where gylist.school_id=$shool_id and gy_class.up=$class");
    $info=mysql_fetch_array($sql);
}
if($cla[up]>'0'){
 $sql=mysql_query("select COUNT(id) as num from gylist where school_id=$shool_id and class_id=$class");   //正式环境为user_id=$_SESSION[name]
 $info=mysql_fetch_array($sql);
}
echo $$cla[up];

//列表设置

$pid_totle=$info[num];
$page_size =2;  //每页显示的条数   
$nums = $pid_totle;   //总条数   
$sub_pages = $pid_totle/$page_size + 1;  //得到当前是第几页     
$pageCurrent=$_GET["p"];  //当前页数  
if(!$pageCurrent){
	$pageCurrent=1;//如果没设定页数默认是第一页 
}
 
$ww=($pageCurrent-1)*$page_size;
//列表结束,下面是获取详细数据
echo $nums;
$sql=$in->getinfo_list($shool_id,$class,$ww,$page_size);  //四个参数分别为：学校id   分类id   后两个无需修改！

while($my_gy=$in->class_fetch($sql)){
    $gy_list[]=array(
		                   "id"=>$my_gy[id],
		                   "title"=>$my_gy[title],
		                   "user"=>$my_gy[name],
		                   "xj"=>$my_gy[xj],
	                       "time"=>date("Y:M:D",$my_gy[time]),
						   "price"=>$my_gy[price],
		                   "class"=>$my_gy[classname]
		                  );
	$smarty->assign("gy_list",$gy_list);
}

$smarty->assign("ROOT",ROOT_PATH); //定义系统根目录

$smarty->display("gy/list.htm");
$subPages=new SubPages($page_size,$nums,$pageCurrent,$sub_pages,"?school=$shool_id&gy_class=$class&p=",2);//分页列表显示



?>